// 「一本通 1.1 例 4」加工生产调度
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
const int MAXN=1000;
int n;
int a[MAXN+1],b[MAXN+1];
struct Node{
    int id;
    int minab;
    bool operator < (const Node other)const{
        return minab<other.minab;
    }
};
Node nodes[MAXN];
queue<int> ateam;
stack<int> bteam;
int team[MAXN];
int ans;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=n;i++){
        Node cur={i,min(a[i],b[i])};
        nodes[i-1]=cur;
    }
    sort(nodes,nodes+n);
    for(int k=0;k<n;k++){
        int i=nodes[k].id;
        int t=nodes[k].minab;
        if (t==a[i]) ateam.push(i);
        else bteam.push(i);
    }
    int i=0;
    while(!ateam.empty()){
        team[i++]=ateam.front();
        ateam.pop();
    }
    while(!bteam.empty()){
        team[i++]=bteam.top();
        bteam.pop();
    }
    int asum=0,bsum=0;
    for(int i=0;i<n;i++){
        asum+=a[team[i]];
        if (asum>bsum) bsum=asum;
        bsum+=b[team[i]];
    }
    cout<<bsum<<endl;
    for(int i=0;i<n;i++) cout<<team[i]<<' ';
}